package com.meizhao.api.controller.common;

import com.meizhao.api.configuration.ConfigProperties;
import com.meizhao.api.service.FileService;
import com.meizhao.api.utils.CheckUtils;
import com.meizhao.api.utils.constants.Keys;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RequestMapping("/att")
@RestController
public class FileController {

    private ConfigProperties configProperties;

    private FileService fileService;

    @Autowired
    public FileController(ConfigProperties configProperties, FileService fileService) {
        this.configProperties = configProperties;
        this.fileService = fileService;
    }

    @PostMapping("/uploadPics")
    public Object uploadPics(MultipartFile[] files, String referenceId) {
        for (MultipartFile file : files) {
            CheckUtils.checkFile(file, configProperties.getFileSizeLimit(), configProperties.getFileTypeLimits());
        }
        //return ResultUtils.success(fileService.saveFiles(files, StringUtils.isNotBlank(referenceId) ? Long.parseLong(referenceId) : null));
        return null;
    }

    @PostMapping("/uploadPic")
    public Object uploadPics(MultipartFile file, String referenceId) {

        CheckUtils.checkFile(file, configProperties.getFileSizeLimit(), configProperties.getFileTypeLimits());
        //return ResultUtils.success(fileService.saveFile(file, StringUtils.isNotBlank(referenceId) ? Long.parseLong(referenceId) : null));
        return null;
    }


    @PostMapping("/uploadAvatar")
    public Object uploadAvatar(MultipartFile file, String referenceId) {

        CheckUtils.checkFile(file, configProperties.getFileSizeLimit(), configProperties.getFileTypeLimits());
        //return ResultUtils.success(fileService.saveAvatar(file,
         //       StringUtils.isNotBlank(referenceId) ? Long.parseLong(referenceId) : null));
        return null;
    }


    @PostMapping("/delPic")
    public Object delPic(String id) {
        CheckUtils.notNull(id, "请选择要删除的图片");
        /*fileService.delPic(Long.parseLong(id));
        return ResultUtils.success();*/
        return null;
    }

    @RequestMapping("/getFileList")
    public Object getFileList(String id){

        CheckUtils.notNull(id, Keys.REQUEST_PARAM_EMPTY);
        //return ResultUtils.success(fileService.getFileList(Long.parseLong(id)));
        return null;
    }
}
